/*年轻人，只管向前看，不要管自暴自弃者的话*/
package com.znb.okdown.ui.fragment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.znb.okdown.databinding.FragmentFltViewBinding
import com.znb.okdown.flutter.FlutterCacheManager
import io.flutter.embedding.android.FlutterView


/**
 * create by itz on 2024/1/17 9:18
 * desc :
 **/
class FltViewFragment : BaseFragment() {

    lateinit var binding: FragmentFltViewBinding

    companion object {
        fun newInstance(): FltViewFragment {
            return FltViewFragment()
        }
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        binding = FragmentFltViewBinding.inflate(inflater, container, false)
        return binding.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        initView()
    }

    private fun initView() {
        val flutterView = FlutterView(requireContext())
        binding.flutterContainer.addView(flutterView)
        FlutterCacheManager.instance.getCacheFlutterEngine(
            requireContext(),
            FlutterCacheManager.SETTING
        )
            ?.let { flutterView.attachToFlutterEngine(it) }
    }
}